package cn.xxstudy.compose

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.MaterialTheme.shapes
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import cn.xxstudy.compose.layout.SimpleLayoutActivity
import cn.xxstudy.compose.material.SimpleMaterialThemeActivity
import cn.xxstudy.compose.ui.theme.ComposeDemoTheme

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeDemoTheme {
                // A surface container using the 'background' color from the theme
                Scaffold(
                    topBar = { TopAppBar(title = { Text(text = "Compose学习") }) },
                    content = { Main() }
                )
            }
        }
    }

    @Preview
    @Composable
    fun Main() {
        LazyColumn(
            modifier = Modifier.padding(horizontal = 5.dp),
            //为每行添加间隔
            verticalArrangement = Arrangement.spacedBy(4.dp)
        ) {
            item {
                Spacer(modifier = Modifier.padding(vertical = 4.dp))
                IntentButton(targetActivity = SimpleLayoutActivity::class.java, "布局")
            }

            item {
                IntentButton(SimpleMaterialThemeActivity::class.java, "Material Design")
            }

        }
    }

    @Composable
    fun TobBarComponent() {
        TopAppBar(title = { Text(text = "Compose学习") })
    }

    @Composable
    fun IntentButton(targetActivity: Class<out Activity>, text: String) {
        Button(onClick = {
            startActivity(Intent(this, targetActivity))
        }, modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape(5.dp),contentPadding = PaddingValues(15.dp)) {
            Text(text = text)
        }
    }


}



